package com.example.flasksale.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/flask-sale")
public class FlaskSaleController {

    @GetMapping("/url")
    public Map<String, String> getUrl(@RequestParam Integer productId) {

        String urlPath = "";

        if (LocalDateTime.now().compareTo(LocalDateTime.parse("2021-04-14T15:00:00")) >= 0) {
            urlPath = "/order/" + productId;
        }

        Map<String, String> result = new HashMap<String, String>();
        result.put("urlPath", urlPath);
        return result;
    }

}
